import 'package:concierge/app/constant.dart';
import 'package:concierge/generated/locales.g.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class DialogButtonParam {
  final bool onlyOneButton;
  final bool showDivider;
  String? leftText;
  String? rightText;
  String? oneBtnText;
  VoidCallback? onLeftTap;
  VoidCallback? onRightTap;
  VoidCallback? onOneBtnTap;

  DialogButtonParam({
    required this.onlyOneButton,
    required this.showDivider,
    this.oneBtnText,
    this.onOneBtnTap,
    this.leftText,
    this.rightText,
    this.onLeftTap,
    this.onRightTap,
  });
}

Future<void> showCommonDialog({
  required String content,
  required DialogButtonParam dialogBtnParam,
}) async {
  await Get.dialog(
    PopScope(
      canPop: false,
      child: Center(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 40),
          child: Material(
            borderRadius: br8,
            child: Container(
              decoration: BoxDecoration(color: Colors.white, borderRadius: br8),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const SizedBox(height: 15),
                  Text("prompt".tr, style: const TextStyle(fontSize: 17)),
                  dialogBtnParam.showDivider
                      ? Padding(
                          padding: const EdgeInsets.only(top: 15),
                          child: Divider(
                            height: 0,
                            color: lineColor,
                            thickness: 0.5,
                          ),
                        )
                      : SizedBox.shrink(),
                  Padding(
                    padding: const EdgeInsets.symmetric(
                      horizontal: 15,
                      vertical: 15,
                    ),
                    child: Text(content, style: const TextStyle(fontSize: 15)),
                  ),
                  Divider(height: 0, color: lineColor, thickness: 0.5),
                  dialogBtnParam.onlyOneButton
                      ? InkWell(
                          onTap: () {
                            Get.back();
                            dialogBtnParam.onOneBtnTap?.call();
                          },
                          child: SizedBox(
                            height: 45,
                            child: Center(
                              child: Text(
                                dialogBtnParam.oneBtnText ?? "OK",
                                style: TextStyle(
                                  fontSize: 16,
                                  color: color_confirm_text_ok,
                                ),
                              ),
                            ),
                          ),
                        )
                      : IntrinsicHeight(
                          child: Row(
                            children: [
                              Expanded(
                                child: InkWell(
                                  onTap: () {
                                    Get.back();
                                    dialogBtnParam.onLeftTap?.call();
                                  },
                                  child: SizedBox(
                                    height: 45,
                                    child: Center(
                                      child: Text(
                                        dialogBtnParam.leftText ??
                                            LocaleKeys.exit.tr,
                                        style: TextStyle(
                                          fontSize: 16,
                                          color: color_confirm_text_cancel,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                              VerticalDivider(
                                indent: 8,
                                endIndent: 8,
                                color: lineColor,
                                thickness: 0.5,
                              ),
                              Expanded(
                                child: InkWell(
                                  onTap: () {
                                    Get.back();
                                    dialogBtnParam.onRightTap?.call();
                                  },
                                  child: SizedBox(
                                    height: 45,
                                    child: Center(
                                      child: Text(
                                        dialogBtnParam.rightText ??
                                            LocaleKeys.agree.tr,
                                        style: TextStyle(
                                          fontSize: 16,
                                          color: color_confirm_text_ok,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                ],
              ),
            ),
          ),
        ),
      ),
    ),
    barrierDismissible: false,
  );
}
